﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

// For MediaPlayer
using WMPLib;
using AxWMPLib;

//Kinect
using Microsoft.Research.Kinect;

namespace InteractiveKidsTV
{
    public partial class formMain : Form
    {
        public formMain()
        {
            InitializeComponent();
        }

        //private bool waiting;

        private void formMain_Load(object sender, EventArgs e)
        {
            player1.uiMode = "none";
        }

        private void buttonPlay_Click(object sender, EventArgs e)
        {
            // autoplays when you set this because autoStart property defaults to true
            player1.URL = @"intro.wmv"; 

            // now need to handle looping - using the playState or PlayStateChanged event?

            // THIS DOESN'T WORK, IGNORE IT
            /*            //how do i find out when the clip ends?
                        while (player1.playState == WMPPlayState.wmppsPlaying)
                        {
                            // wait until it stops playing
                        }
                        //then move on to the next video
                        waiting = true;
                        player1.URL = @"C:\Users\Owner\Videos\request.wmv";
                        while (waiting)
                        {
                            while (player1.playState == WMPPlayState.wmppsPlaying)
                            {// wait until it stops playing
                            }
                            //repeat the video
                            player1.URL = @"C:\Users\Owner\Videos\request.wmv";
                        }
                        //no longer waiting, so switch to next video
                        player1.URL = @"C:\Users\Owner\Videos\confirmation.wmv";
            */
        }

        private void buttonStop_Click(object sender, EventArgs e)
        {
            player1.Ctlcontrols.stop();
        }

        private void buttonRespond_Click(object sender, EventArgs e)
        {
            //waiting = false;
        }

        private void player1_MediaError(object sender, _WMPOCXEvents_MediaErrorEvent e)
        {
            try
            // If the Player encounters a corrupt or missing file, 
            // show the hexadecimal error code and URL.
            {
                IWMPMedia2 errSource = e.pMediaObject as IWMPMedia2;
                IWMPErrorItem errorItem = errSource.Error;
                MessageBox.Show("Error " + errorItem.errorCode.ToString("X")
                                + " in " + errSource.sourceURL);
            }
            catch (InvalidCastException)
            // In case pMediaObject is not an IWMPMedia item.
            {
                MessageBox.Show("Error." + e.ToString());
            } 
        }
    }
}
